package javaweb_work01.login.Dao;

import javaweb_work01.login.Entity.User;
import javaweb_work01.login.Utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoImp implements UserDao{
    @Override
    public User userLogin(User user) {
        try {
            //使用连接池创建QueryRunner对象
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
            //编写sql语句
            String sql = "select * from user where userName = ? and password = ?";
            //执行语句
            User query = qr.query(sql, new BeanHandler<User>(User.class), user.getUserName(), user.getPassword());
            //返回结果
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //如果查找失败返回null
        return null;
    }
}
